package com.example.canteen.service.impl;

import com.example.canteen.dao.StudentDao;
import com.example.canteen.dao.impl.StudentDaoImpl;
import com.example.canteen.domain.Admin;
import com.example.canteen.domain.Student;
import com.example.canteen.service.StudentService;

import java.util.List;

public class StudentServiceImpl implements StudentService {
    private StudentDao studentDao = new StudentDaoImpl();
    @Override
    public boolean register(Student student) {
        Student s = studentDao.findById(student.getId());
        if(s!=null) {
            return false;
        }
        studentDao.save(student);
        return true;
    }

    @Override
    public Student login(int id, String password) {
        return studentDao.findByUsernameAndPassword(id, password);

    }

    @Override
    public boolean update(Student student) {
     if(studentDao.update(student)==0) {
         return false;
     }
     return true;
    }

    @Override
    public List<Student> findAll() {
        return studentDao.findAll();
    }

    @Override
    public boolean delete(int id) {
        if (studentDao.delete(id)==0) {
            return false;
        }
        return true;
    }

    @Override
    public Student findById(int id) {
        Student a = studentDao.findById(id);
        return a;
    }
}
